const moment = require('moment');

// 格式化时间
const formatDateTime = (date) => {
  return moment(date).format('YYYY-MM-DD HH:mm:ss');
};

// 格式化电子书类型数据
const formatBookTypes = (rows) => {
  return rows.map(row => ({
    ...row,
    created_at: formatDateTime(row.created_at)
  }));
};

// 格式化电子书数据
const formatBookData = (book, chapters = null) => {
  const formattedBook = {
    ...book,
    created_at: formatDateTime(book.created_at),
    updated_at: formatDateTime(book.updated_at)
  };

  if (chapters) {
    formattedBook.chapters = chapters;
  }

  return formattedBook;
};

module.exports = {
  formatDateTime,
  formatBookTypes,
  formatBookData
};